package cn.wanho.controller.teacher;


import cn.hutool.core.date.DateUtil;
import cn.wanho.CmsUserThreadLocal.UserThreadLocal;
import cn.wanho.dto.CmsClassStage;
import cn.wanho.dto.CmsExam;
import cn.wanho.rvo.ResultVO;
import cn.wanho.service.CmsTeacherService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private CmsTeacherService teacherService;



    /**
     * 默认查看的是老师当前所带班级的学生信息
     */

    @GetMapping("/selectTeacherInclassStudent")

    public ResultVO selectDefaultStudents(Integer page,Integer rows){
        Integer teacherId = UserThreadLocal.get().getId();
        return  teacherService.selectDefaultStudents(teacherId,page,rows);
    }
    /**
     * 查看该老师当前所带的班级
     * @return
     */
    @GetMapping("/selectTeacherInClass")
    public ResultVO  selectAllStudent(){
        Integer teacherId = UserThreadLocal.get().getId();
        return  teacherService.selectTeacherInClass(teacherId);

    }



    /**
     * 根据id查找学生信息
     */
    @GetMapping("/selectStudentBystuId")
    public ResultVO selectStudentBystuId(Integer studentId){
        return  teacherService.selectStudentBystuId(studentId);
    }


    /**
     * 根据班级id查询该班级的学生
     */

    @GetMapping("selectStudentsByClassId")
    public ResultVO selectStudentsByClassId(Integer classId){

        return teacherService.selectStudentsByClassId(classId);
    }


    /**
     * 修改老师个人信息（含头像）
     */
    @PostMapping("/modifySelf")
    public  ResultVO modifySelf(MultipartFile icon,String introduction) throws IOException {
        Integer teacherId = UserThreadLocal.get().getId();
        return teacherService.modifySelf(icon.getBytes(),introduction,teacherId);
    }


    /**
     * 创建试卷并设置考试时间
     */
    @PostMapping("/setPaperAndStage")
    public ResultVO setPaperAndStage(CmsClassStage cmsClassStage){
        return teacherService.setPaperAndStage(cmsClassStage);

    }


    /**
     * 单题打分
     */

    @PostMapping("/setScore")
    public ResultVO setScore(Integer questionId,Integer score){

        return  teacherService.setScore(questionId,score);
    }

    /**
     *目前授课的班级以及对阶段和目前当前所处阶段完结剩余的时间
     * @return
     */
    @GetMapping("/selectPresentClass")
    public  ResultVO selectPresentClass(){
        Integer teacherId = UserThreadLocal.get().getId();
        return teacherService.selectPresentClass(teacherId);
    }
    /**
     * 计算总分
     */
    @PostMapping("/getSumScore")
    public  ResultVO getSumScore(Integer studentId,Integer paperId){
        // Integer teacherId = UserThreadLocal.get().getId();
        return teacherService.getSumScore(studentId ,paperId);
    }



    /**
     * 简答题打分(redis)
     */

    @PostMapping("/setScore2")
    public ResultVO setScore2(Integer studentId,Integer paperId,Integer questionId,Integer score){
        return  teacherService.setScore2(studentId,paperId,questionId,score);
    }

}
